package cn.kbblog.biz;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kbblog.dao.BaseDao;
import cn.kbblog.dao.DepartDao;
import cn.kbblog.entity.Depart;

@Service
public class DepartBiz extends BaseBiz<Depart>{
	@Resource
	private DepartDao dao;
	@Resource
	private BaseDao baseDao;
	@Autowired
	private SQLManager sqlManager;

	public void getDepartPage() {
		int pageSize = 100;
		int page = 6000;
		Integer start = pageSize*(page-1)+1,end=pageSize*page;		
		long s = System.currentTimeMillis();
		//jdbcTemplate 分页查询
//		String sql = "select * from Depart";
//		List<Map<String, Object>> list = baseDao.selectPageByMysql(sql, page, pageSize);
//		System.out.println("耗时："+(System.currentTimeMillis() - s)+"数据大小："+list.size());
		
		//beetlsql 分页
//		List<Depart> list = dao.all(start, pageSize);
//		System.out.println("耗时："+(System.currentTimeMillis() - s)+"数据大小："+list.size());
		
//		dao.allCount();
		List<Depart> list = dao.queryDepartList("测试部门_1",start, pageSize);
		System.out.println("耗时："+(System.currentTimeMillis() - s)+"数据大小："+list.size());
		
//		PageQuery query = new PageQuery(6000, new HashMap(){{put("keyWord", "测试部门_1");}});
//		query.setPageSize(50);
//		dao.queryDepartPage(query);
//		List list = query.getList();
//		System.out.println("耗时："+(System.currentTimeMillis() - s)+"数据大小："+list.size());
		
//		try {
//			List<Depart> list = sqlManager.execute(new SQLReady("select * from Depart limit 6000,100"),Depart.class);
//			System.out.println("耗时："+(System.currentTimeMillis() - s)+"数据大小："+list.size());
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}
	
	public void saveDepart() {
		for(int i=1;i<=50;i++){
			List<Depart> list = new ArrayList<Depart>();
			for(int j=1;j<=100000;j++){
				Depart depart = new Depart("测试部门_"+i+"_"+j);
				list.add(depart);
			}
			this.dao.insertBatch(list);
		}
		
	}
	
}
